﻿/****************************** Module Header ******************************\
 * Module Name:  _Response.cs
 * Module Version:  1.0.0 (2012-9-16)
 * Copyright (c) AnyEB.Com (14507247@qq.com)
 * 
 * This class is used for _Request.
 * 
 * This source is subject to the GPL License.
 * See http://www.gnu.org/licenses/gpl.html.
 * All other rights reserved.
 * 
 * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, 
 * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED 
 * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
\***************************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace UCF.Core.Web
{
    public class _Response
    {
        public static HttpResponse Response { get { return HttpContext.Current.Response; } }

        public static void Write(string s, params object[] args)
        {
            Response.Write(args.Length > 0 ? string.Format(s, args) : s);
        }
        public static void WriteEnd(string s, params object[] args)
        {
            Response.Write(args.Length > 0 ? string.Format(s, args) : s);
            Response.End();
        }
        public static void Redirect(string s, bool endResponse = false)
        {
            HttpContext.Current.Response.Redirect(s, endResponse);
        }

        public static void TimerRedirect(string s, string url, bool showCountdown = true, int time = 3)
        {
            if (url.Length == 0) url = _Url.Url.ToString();
            Response.Write(s);
            string jstip = string.Empty;
            if (showCountdown)
            {
                jstip = "document.getElementById('panCountDown').innerHTML=i;";
                Response.Write(string.Format("<div style='font-size:12px'><span id='panCountDown'>{0}</span>秒后即将 <a href=\"{1}\">跳转</a> ...</div>", time, url));
            }
            Response.Write(string.Format("<script type='text/javascript'>var i={0};var timer=setInterval(function(){{i--;{2}if(i==0){{location.href='{1}';clearInterval(timer)}}}},1000);</script>", time, url, jstip));
            Response.End();
        }

        public static void WriteJScript(string s, bool endResponse = true)
        {
            HttpContext.Current.Response.Write(string.Format("<script type='text/javascript'>{0}</script>", s));
            if (endResponse) HttpContext.Current.Response.End();
        }
    }
}
